//
//  NewListDetailViewController.m
//  XWZ_News_Work
//
//  Created by dllo on 16/1/15.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "NewListDetailViewController.h"
#import "NewListAllTableViewCell.h"
#import "NewListDetailTableViewCell.h"

@interface NewListDetailViewController ()<UITableViewDelegate, UITableViewDataSource, NewListTableViewCellDelegate, NewListTableViewCellDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *allArr;
@property (nonatomic, strong) NSMutableArray *didArr;

@end

@implementation NewListDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createTableView];
    [self createArr];
    
    
    
}

-(void)createArr
{
    self.allArr = [NSMutableArray arrayWithObjects:@"NBA", @"社会", @"影视", @"足球", @"CBA", @"跑步", @"科技", @"手机", @"数码", @"互联网", @"家居", @"旅游", @"读书", @"酒香", @"教育", @"亲子", @"暴雪", @"漫画", @"感情", @"艺术", @"值得买", @"博客", @"论坛", nil];
    self.didArr = [NSMutableArray arrayWithObjects:@"头条", @"娱乐", @"热点", @"体育", @"财经", @"汽车", @"时尚", @"图片", @"跟帖", @"房产", @"时尚", @"图片", @"房产", @"军事", @"段子", @"历史", @"原创", @"健康", @"政务", nil];
}


- (void)createTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.bounces = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    
    
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (0 == section) {
        return @"切换栏目专栏";
    } else {
    
    return @"点击添加更多栏目";
    
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (0 == indexPath.section) {
        return (self.didArr.count / 4) * 35 * HEIGHT + 80;
    } else {
    
        return (self.allArr.count / 4) * 35 * HEIGHT;
       
    
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (0 == indexPath.section) {
        static NSString *cellDetail = @"cellD";
        NewListDetailTableViewCell *cellD = [tableView dequeueReusableCellWithIdentifier:cellDetail];
        if (nil == cellD) {
            cellD = [[NewListDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellDetail];
        }
        cellD.selectionStyle = UITableViewCellSelectionStyleNone;
        cellD.label.text = @"点击移除";
        cellD.arr = self.didArr;
        cellD.delegate = self;
   
        return cellD;
    } else {
    
        static NSString *cellAll = @"cellA";
        NewListDetailTableViewCell *cellA = [tableView dequeueReusableCellWithIdentifier:cellAll];
        if (nil == cellA) {
            cellA = [[NewListDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellAll];
        }
        cellA.selectionStyle = UITableViewCellSelectionStyleNone;
        cellA.arr = self.allArr;
        cellA.dataSource = self;
     
        return cellA;
    
    }
    
    
}

- (void)changeListByIndex:(NSInteger)index
{
    NSString *str = [self.didArr objectAtIndex:index];
    [self.didArr removeObjectAtIndex:index];
    [self.allArr addObject:str];
    [self.tableView reloadData];
    NSLog(@"%ld", self.allArr.count);
    
}



- (void)allToDidByIndex:(NSInteger)index
{
    NSString *str = [self.allArr objectAtIndex:index];
    [self.allArr removeObjectAtIndex:index];
    
    [self.didArr addObject:str];
    [self.tableView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
